//
//  YZDoctorTableViewCell.m
//  kuaiyi
//
//  Created by WGP on 16/5/5.
//
//

#import "YZDoctorTableViewCell.h"
#import "YZDoctorModel.h"
#import <UIImageView+WebCache.h>
#import "UIImage+AsyncDraw.h"
#import "SDWebImageDownloader.h"

@interface YZDoctorTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *hospitalName;
@property (weak, nonatomic) IBOutlet UILabel *otherLabel;
@property (weak, nonatomic) IBOutlet UIButton *flowerBtn;
@property (weak, nonatomic) IBOutlet UIButton *shousuBtn;
@property (weak, nonatomic) IBOutlet UIButton *jiqiBtn;
@property (weak, nonatomic) IBOutlet UILabel *pipeiduLabel;


@end
static NSString *ID = @"doctorCell";
@implementation YZDoctorTableViewCell

+(instancetype)doctorCellWith:(UITableView *)tableView
{
    YZDoctorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        
        cell = [[NSBundle mainBundle] loadNibNamed:@"YZDoctorTableViewCell" owner:nil options:nil].lastObject;
        cell.iconView.layer.cornerRadius = 32;
        cell.iconView.layer.masksToBounds = YES;
    }
    return cell;
}

-(void)setDoctorModel:(YZDoctorModel *)doctorModel
{
    _doctorModel = doctorModel;
    
    
    
//    [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:doctorModel.doctor_portraitURL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//        
//    } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
//        if (image == nil) {
//            
//            UIImage *defaultImage = [UIImage imageNamed:@"doctor_defaultphoto_male"];
//            [defaultImage WP_AsyncDrawImageWith:defaultImage.size bgColor:[UIColor whiteColor] isCorner:YES finished:^(UIImage *image) {
//                self.iconView.image = image;
//            }];
//            
//        }else
//        {
//            [image WP_AsyncDrawImageWith:image.size bgColor:[UIColor whiteColor] isCorner:YES finished:^(UIImage *image) {
//                self.iconView.image = image;
//            }];
//        }
//    }];
    
     UIImage *defaultImage = [UIImage imageNamed:@"doctor_defaultphoto_male"];
    [self.iconView sd_setImageWithURL:doctorModel.doctor_portraitURL placeholderImage:defaultImage];
    
    self.nameLabel.text = doctorModel.doctor_name;
    self.hospitalName.text = doctorModel.doctor_hospital_name;
    self.otherLabel.text = doctorModel.doctor_title_name;
    
    [self.flowerBtn setTitle:[NSString stringWithFormat:@"%zd",[doctorModel.flower intValue]] forState:UIControlStateNormal];
    [self.shousuBtn setTitle:[NSString stringWithFormat:@"%zd",[doctorModel.operation_count intValue]] forState:UIControlStateNormal];
    [self.jiqiBtn setTitle:[NSString stringWithFormat:@"%zd",[doctorModel.banner intValue]] forState:UIControlStateNormal];
    self.pipeiduLabel.text = doctorModel.accuracy;
}

@end
